package com.sgb.kjwl.viewmodel.material;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.text.TextUtils;
import android.view.Gravity;
import android.widget.Toast;

import androidx.core.util.Pair;
import androidx.databinding.ObservableField;

import com.chuanglan.shanyan_sdk.OneKeyLoginManager;
import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.NewAPIManager;
import com.sgb.kjwl.model.EnquiryImAlternateEntity;
import com.sgb.kjwl.model.entity.CompanyDetailsEntity;
import com.sgb.kjwl.model.entity.CompanyStatusEntity;
import com.swgk.core.base.aroute.AppRouteConstant;
import com.swgk.core.base.model.entity.ListResponse;
import com.swgk.core.common.utils.ActivityJump;
import com.swgk.core.dialog.RoundDialog;
import com.swgk.core.view.entity.GoodsPublishEntity;
import com.sgb.kjwl.model.entity.GoodsSkuDetailEntity;
import com.sgb.kjwl.model.entity.LoginEntity;
import com.sgb.kjwl.model.entity.MaterialCompanyEntity;
import com.sgb.kjwl.model.entity.MaterialDetailEntity;
import com.sgb.kjwl.model.entity.ShoppingCarRequest;
import com.sgb.kjwl.model.entity.UserMsgEntity;
import com.sgb.kjwl.model.entity.shopping.ShoppingCarResponse;
import com.sgb.kjwl.model.entity.user.OneKeyLoginEntity;
import com.sgb.kjwl.model.entity.user.RecommendListEntity;
import com.sgb.kjwl.model.entity.user.SkuInfoEntity;
import com.sgb.kjwl.model.entity.user.SkuItemAttrEntity;
import com.sgb.kjwl.repository.MaterialRepertory;
import com.sgb.kjwl.view.ui.activity.self.shop.ShopGoodsDetailActivity;
import com.sgb.kjwl.view.ui.activity.self.userInfo.SetPwdActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MLog;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;
import com.swgk.core.view.entity.GoodsPublishEntity;

import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.jpush.android.api.JPushInterface;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @author Administrator
 */
public class ShopGoodsDetailModel extends BaseViewModel {
    public ObservableField<String> shopImAccount = new ObservableField<>("");
    public ObservableField<MaterialDetailEntity> materialDetailEntity = new ObservableField<>();
    public ObservableField<GoodsSkuDetailEntity> goodsSkuDetailEntity = new ObservableField<>();
    private final MaterialRepertory repertory;
    private final ShopGoodsDetailActivity activity;

    public ShopGoodsDetailModel(ShopGoodsDetailActivity activity, MaterialRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }


    public void getDetailModel(String pid, String skuId) {
        DialogHelper.showProgressDialog2(activity, null, "数据加载中...", 0, false, null, false);

        NewAPIManager.getInstance().getGoodsAPI().getSkuDetail(pid, skuId).enqueue(new ICallBack<BaseEntity<GoodsSkuDetailEntity>>() {
            @Override
            public void onSuccess(BaseEntity<GoodsSkuDetailEntity> data) {
                if (data == null || data.getData() == null) {
                    MToast.showToast(activity, "服务器异常~");
                    return;
                }
                activity.showProductInfo(data.getData());
                goodsSkuDetailEntity.set(data.getData());
            }
        });
    }

    public void getCompanyModel(String cid) {
        NewAPIManager.getInstance().getGoodsAPI().getMaterialShopDetail(cid).enqueue(new Callback<BaseEntity<MaterialCompanyEntity>>() {
            @Override
            public void onResponse(@NotNull Call<BaseEntity<MaterialCompanyEntity>> call, @NotNull Response<BaseEntity<MaterialCompanyEntity>> response) {
                if (response.body() == null || response.body().getData() == null) {
                    MToast.showToast(activity, "服务器异常~");
                    return;
                }
                activity.showCompanyInfo(response.body().getData());
            }

            @Override
            public void onFailure(@NotNull Call<BaseEntity<MaterialCompanyEntity>> call, @NotNull Throwable t) {

            }
        });
    }

    /****
     * 获取供应商的详细信息
     * @param companyId
     */
    public void getCompanyInformation(String companyId) {
        NewAPIManager.getInstance().getMaterialAPI().getGoodsCompanyInfoDetailsFront(companyId).enqueue(new Callback<BaseEntity<CompanyDetailsEntity>>() {
            @Override
            public void onResponse(@NotNull Call<BaseEntity<CompanyDetailsEntity>> call, @NotNull Response<BaseEntity<CompanyDetailsEntity>> response) {
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    activity.showCompanyInfoDetail(response.body().getData());
                }
            }

            @Override
            public void onFailure(@NotNull Call<BaseEntity<CompanyDetailsEntity>> call, @NotNull Throwable t) {

            }
        });
    }

    public void getGoodsItemInformationById(String id) {
        DialogHelper.showProgressDialog2(activity, null, "数据加载中...", 0, false, null, false);
        NewAPIManager.getInstance().getGoodsReleasedAPI().getNewGoodsById(id).enqueue(new ICallBack<BaseEntity<GoodsPublishEntity>>() {
            @Override
            public void onSuccess(BaseEntity<GoodsPublishEntity> data) {
                activity.setGoodsItemInformation(data.getData());
            }
        });
    }

    public String getAreaCode() {
        return repertory.getAreaCode();
    }

    /***
     * 加入采购单
     * @param shoppingCarRequest
     */
    public void addShoppingCar(ShoppingCarRequest shoppingCarRequest, boolean isPurchase) {
        if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
            DialogHelper.showProgressDialog2(activity, null, "数据加载中...", 0, false, null, false);
        }
        NewAPIManager.getInstance().getShoppingCarNewOrderAPI().addShoppingCar(shoppingCarRequest).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(@NotNull Call<BaseEntity> call, @NotNull Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    MToast.showToast(activity, "服务器异常");
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    if (isPurchase) {
                        getShoppingCarInfo();
                    } else {
                        MToast.showToast(activity, response.body().getMsg());
                        getCarCount();
                    }

                } else {
                    MToast.showToast(activity, response.body().getMsg());
                    if ("商品已下架".equals(response.body().getMsg())) {
                        activity.setAddButton();
                    }
                }
            }

            @Override
            public void onFailure(@NotNull Call<BaseEntity> call, @NotNull Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    /***
     *根据UserId获取购物车数量
     */
    public void getCarCount() {
        NewAPIManager.getInstance().getShoppingCarNewOrderAPI().getCarCount().enqueue(new Callback<BaseEntity<Integer>>() {
            @Override
            public void onResponse(@NotNull Call<BaseEntity<Integer>> call, @NotNull Response<BaseEntity<Integer>> response) {
                if (response == null || response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    activity.refreshCarCount(response.body().getData());
                }
            }

            @Override
            public void onFailure(@NotNull Call<BaseEntity<Integer>> call, @NotNull Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    /***
     * 获取购物车列表数据
     * @param
     */
    public void getShoppingCarInfo() {
        DialogHelper.showProgressDialog2(activity, null, "数据加载中...", 0, false, null, false);

        NewAPIManager.getInstance().getShoppingCarNewOrderAPI().getShoppingCarEntity().enqueue(new Callback<BaseEntity<List<ShoppingCarResponse>>>() {
            @Override
            public void onResponse(@NotNull Call<BaseEntity<List<ShoppingCarResponse>>> call, @NotNull Response<BaseEntity<List<ShoppingCarResponse>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    activity.showShoppingCarDetail(response.body().getData());
                } else {
                    MToast.showToast(activity.getActivity(), response.body().getMsg());
                }
            }

            @Override
            public void onFailure(@NotNull Call<BaseEntity<List<ShoppingCarResponse>>> call, @NotNull Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getAuthInfo() {
        APIManager.getInstance().getUserAPI().getUserInfo().enqueue(new Callback<BaseEntity<UserMsgEntity>>() {
            @Override
            public void onResponse(@NotNull Call<BaseEntity<UserMsgEntity>> call, @NotNull Response<BaseEntity<UserMsgEntity>> response) {
                if (response == null || response.body() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    if (response.body().getData() == null) {
                        return;
                    }
                    if (response.body().getData().isRelevance()) {
                        //企业认证成功
                        getCarCount();
                    }
                }
            }

            @Override
            public void onFailure(@NotNull Call<BaseEntity<UserMsgEntity>> call, @NotNull Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    @Deprecated
    public void checkToken(String tag) {
        if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
            DialogHelper.showProgressDialog2(activity, null, "数据加载中...", 0, false, null, false);
        }
        APIManager.getInstance().getShoppingCarAPI().checkToken().enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(@NotNull Call<BaseEntity> call, @NotNull Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response == null || response.body() == null || response.body().getState() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    if ("shopping_car".equals(tag)) {
                        activity.checkTokenView();
                    } else {
                        activity.checkAddTokenView(false);
                    }
                } else {
                    if (!"Miss_Permission".equals(response.body().getCode())) {
                        MToast.showToast(activity, response.body().getMsg());
                        activity.toLogin();
                    } else {
                        MToast.showToast(activity, response.body().getMsg());
                    }
                }
            }

            @Override
            public void onFailure(@NotNull Call<BaseEntity> call, @NotNull Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void oneKeyLogin(OneKeyLoginEntity oneKeyLoginEntity) {
        if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
            DialogHelper.showProgressDialog2(activity, null, "数据加载中...", 0, false, null, false);
        }
        APIManager.getInstance().getUserAPI().oneClickLogin(oneKeyLoginEntity).enqueue(new Callback<BaseEntity<LoginEntity>>() {
            @Override
            public void onResponse(@NotNull Call<BaseEntity<LoginEntity>> call, @NotNull Response<BaseEntity<LoginEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response == null || response.body() == null) {
                    return;
                }
                if (response.body().getState() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    OneKeyLoginManager.getInstance().finishAuthActivity();
                    if (response.body().getData().isNeedRegister()) {
                        Intent intent = new Intent(activity, SetPwdActivity.class);
                        intent.putExtra("mobile", response.body().getData().getPhone());
                        activity.startActivity(intent);
                    } else {
                        //登录成功逻辑
                        loginImModel(response);

                        /*saveUserInfo(response.body().getData());
                        activity.loginSucceed(response.body().getData(), response.body().getData().getPhone());
                        SharedPreferenceUtil.getInstance().saveData(SharedPreferenceUtil.LOGIN_TOKEN, response.body().getData().getToken());
                        SharedPreferenceUtil.getInstance().saveData(SharedPreferenceUtil.LOGIN_PHONE, response.body().getData().getPhone());
                        JPushInterface.setAlias(activity, 1, response.body().getData().getPhone());
                        getUserInfo();*/
                    }
                }
            }

            @Override
            public void onFailure(@NotNull Call<BaseEntity<LoginEntity>> call, @NotNull Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    //网易IM登陆
    private void loginImModel(Response<BaseEntity<LoginEntity>> response) {
//        NimUIKit.login(new LoginInfo(response.body().getData().getImAccount(), response.body().getData().getImToken()), new RequestCallback<LoginInfo>() {
//            @Override
//            public void onSuccess(LoginInfo param) {
        DialogHelper.dismissProgressDialog();
        SharedPreferenceUtil.getInstance().cleatData();
        saveUserInfo(response.body().getData());
        MToast.showToast(activity, "登录成功");
        activity.loginSucceed(response.body().getData(), response.body().getData().getPhone());
        SharedPreferenceUtil.getInstance().saveData(SharedPreferenceUtil.LOGIN_TOKEN, response.body().getData().getToken());
        SharedPreferenceUtil.getInstance().saveData(SharedPreferenceUtil.LOGIN_PHONE, response.body().getData().getPhone());
        JPushInterface.setAlias(activity, 1, response.body().getData().getPhone());
        getUserInfo();
//            }
//
//            @Override
//            public void onFailed(int code) {
//                DialogHelper.dismissProgressDialog();
//            }
//
//            @Override
//            public void onException(Throwable exception) {
//                DialogHelper.dismissProgressDialog();
//            }
//        });
    }

    public void getUserInfo() {
        if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
            DialogHelper.showProgressDialog(activity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        APIManager.getInstance().getUserAPI().getUserInfo().enqueue(new Callback<BaseEntity<UserMsgEntity>>() {
            @Override
            public void onResponse(@NotNull Call<BaseEntity<UserMsgEntity>> call, @NotNull Response<BaseEntity<UserMsgEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response == null || response.body() == null) {
                    return;
                }
                if (response.body().getData() == null) {
                    return;
                }
                if (APIManager.RESPONSE_OK.equals(response.body().getState())) {
                    activity.getUserMsgSucceed(response.body().getData());
                } else {
                    MToast.showToast(activity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(@NotNull Call<BaseEntity<UserMsgEntity>> call, @NotNull Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    //获取商家对应im账户信息
    @SuppressLint("CheckResult")
    public void getShopImInfo(String shopId) {
        repertory.getShopImInfo(shopId)
                .subscribe(shopImEntityBaseEntity -> {
                    if (shopImEntityBaseEntity.getState().equals(AppConstant.REQEUST_SECCUESS)) {
                        shopImAccount.set(shopImEntityBaseEntity.getData().getImAccount());
                    }
                }, throwable -> MLog.d(AppConstant.API_LOG, "error " + throwable.getMessage()));
    }

    public void userFocusCompany(String shopId) {
        if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
            DialogHelper.showProgressDialog(activity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        APIManager.getInstance().getGoodsAPI().userFocusCompany(shopId).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(@NotNull Call<BaseEntity> call, @NotNull Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response == null || response.body() == null) {
                    return;
                }
                if ("ok".equals(response.body().getState())) {
                    activity.setuserFocusCompanyStatus();
                } else {
                    Toast.makeText(activity, response.body().getMsg(), Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onFailure(@NotNull Call<BaseEntity> call, @NotNull Throwable t) {
                DialogHelper.dismissProgressDialog();
                MLog.d(AppConstant.API_LOG, "error " + t.getMessage());
            }
        });
    }

    public void getuserFocusCompanyStatus(String shopId) {
        if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
            DialogHelper.showProgressDialog(activity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        APIManager.getInstance().getGoodsAPI().getuserFocusCompanyStatus(shopId).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(@NotNull Call<BaseEntity> call, @NotNull Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response == null || response.body() == null) {
                    return;
                }
                if ("ok".equals(response.body().getState())) {
                    activity.setuserFocusCompanyStatus((Boolean) response.body().getData());
                } else {
//                    Toast.makeText(activity, response.body().getMsg(), Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onFailure(@NotNull Call<BaseEntity> call, @NotNull Throwable t) {
                DialogHelper.dismissProgressDialog();
                MLog.d(AppConstant.API_LOG, "error " + t.getMessage());
            }
        });
    }

    /**
     * @param skuId 时间：2021.10.19
     *              接口迁移后，参数传递的商品skuId，可能有问题（skuId会动态变化）
     */
    public void getUserFocusStatus(String skuId) {
        Map<String, Object> paramMap = new HashMap<>(1);
        paramMap.put("skuid", skuId);
        NewAPIManager.getInstance().getGoodsAPI().getuserFocusStatus(paramMap).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(@NotNull Call<BaseEntity> call, @NotNull Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if ("ok".equals(response.body().getState())) {
                    activity.setUserFocusStatus((Boolean) response.body().getData(), 0);
                } else {
//                    Toast.makeText(activity, response.body().getMsg(), Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onFailure(@NotNull Call<BaseEntity> call, @NotNull Throwable t) {
                DialogHelper.dismissProgressDialog();
                MLog.d(AppConstant.API_LOG, "error " + t.getMessage());
            }
        });
    }

    /**
     * * 时间：2021.10.19
     * * 接口迁移后，参数传递的商品skuId，可能有问题（skuId会动态变化）
     *
     * @param skuId
     * @param flag
     */
    public void userFocus(String skuId, int flag) {
        if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
            DialogHelper.showProgressDialog2(activity, null, "数据加载中...", 0, false, null, false);
        }
        NewAPIManager.getInstance().getGoodsAPI().userFocus(skuId).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(@NotNull Call<BaseEntity> call, @NotNull Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if ("ok".equals(response.body().getState())) {
                    activity.setUserFocusStatus(flag);
                } else {
                    Toast.makeText(activity, response.body().getMsg(), Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onFailure(@NotNull Call<BaseEntity> call, @NotNull Throwable t) {
                DialogHelper.dismissProgressDialog();
                MLog.d(AppConstant.API_LOG, "error " + t.getMessage());
            }
        });
    }

    private void saveUserInfo(LoginEntity loginEntity) {
        repertory.saveToken(loginEntity.getToken());
        repertory.saveAccount(loginEntity.getPhone());

//        NimUIKit.setAccount(loginEntity.getImAccount());
//        AVChatKit.setAccount(loginEntity.getImAccount());
        //Preferences.saveUserAccount(loginEntity.getImAccount());
        //       Preferences.saveUserToken(loginEntity.getImToken());
    }


    public void getGoodsAttributeEnabled(Map map) {
        if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
            DialogHelper.showProgressDialog2(activity, null, "数据加载中...", 0, false, null, false);
        }

        NewAPIManager.getInstance().getGoodsAPI().getGoodsAttributeEnabled(map).enqueue(new Callback<BaseEntity<SkuInfoEntity>>() {
            @Override
            public void onResponse(@NotNull Call<BaseEntity<SkuInfoEntity>> call, @NotNull Response<BaseEntity<SkuInfoEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    //由于ios和pc端在没有规格都可以购买，与其保持统一，这里会将传过来的skuId置为null，做个判断
                    if (!TextUtils.isEmpty(response.body().getData().getSkuId())) {
                        ShopGoodsDetailActivity.skuId = response.body().getData().getSkuId();
                    }
                    List<SkuItemAttrEntity> skuItemAttrEntitys = response.body().getData().getList();
                    /*Map<String, String> attribute = (Map<String, String>) map.get("attribute");
                    for (Map.Entry<String, String> entry : attribute.entrySet()) {
                        for(SkuItemAttrEntity skuItemAttrEntity : skuItemAttrEntitys){
                            if (entry.getKey().equals(skuItemAttrEntity.getId())){
                                for (int i = 0; i<skuItemAttrEntity.getList().size(); i++){
                                    if (entry.getValue().equals(skuItemAttrEntity.getList().get(i).getValId())){
                                        skuItemAttrEntity.getList().get(i).setChecked(true);
                                    }else {
                                        skuItemAttrEntity.getList().get(i).setChecked(false);
                                    }
                                }
                            }

                        }
                        System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
                    }*/
                    if (skuItemAttrEntitys != null && goodsSkuDetailEntity.get().getItemAttr() != null) {
                        goodsSkuDetailEntity.get().getItemAttr().setSku(skuItemAttrEntitys);
                        activity.setGoodsAttributeEnabled(skuItemAttrEntitys);
                    }
                } else {
                    MToast.showToast(activity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(@NotNull Call<BaseEntity<SkuInfoEntity>> call, @NotNull Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getRecommendList(String id, String skuId) {
        Map<String, Object> map = new HashMap<>(4);
        map.put("id", id);
        map.put("excludeSkuId", skuId);
        map.put("page", 1);
        map.put("limit", 6);
        NewAPIManager.getInstance().getGoodsAPI().getGoodsDetailsRecommendList(map).enqueue(new Callback<BaseEntity<ListResponse<List<RecommendListEntity>>>>() {
            @Override
            public void onResponse(@NotNull Call<BaseEntity<ListResponse<List<RecommendListEntity>>>> call, @NotNull Response<BaseEntity<ListResponse<List<RecommendListEntity>>>> response) {
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    activity.getRecommendList(response.body().getData().getList());
                } else {
                    MToast.showToast(activity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(@NotNull Call<BaseEntity<ListResponse<List<RecommendListEntity>>>> call, @NotNull Throwable t) {

            }
        });
    }

    /**
     * 获取平台声明的标签
     */
    public void getPlatformStatement() {
        APIManager.getInstance().getGoodsAPI().getPlatformStatement().enqueue(new Callback<BaseEntity<String>>() {
            @Override
            public void onResponse(@NotNull Call<BaseEntity<String>> call, @NotNull Response<BaseEntity<String>> response) {
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    activity.getPlatformStatement(response.body().getData());
                } else {
                    MToast.showToast(activity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(@NotNull Call<BaseEntity<String>> call, @NotNull Throwable t) {

            }
        });
    }

    public void itemImAlternate(String shopId, Integer type) {
        if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
            DialogHelper.showProgressDialog2(activity, null, "数据加载中...", 0, false, null, false);
        }
        NewAPIManager.getInstance().getCommonAPI().itemImAlternate(shopId, type).enqueue(new Callback<BaseEntity<EnquiryImAlternateEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<EnquiryImAlternateEntity>> call, Response<BaseEntity<EnquiryImAlternateEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    if (response.body().getData().getConfirmType() != null && 2 == response.body().getData().getConfirmType()) {
                        if (!TextUtils.isEmpty(response.body().getData().getConfirmMessage())) {
                            MToast.showToast(activity, response.body().getData().getConfirmMessage());
                        }
                    } else {
                        List<EnquiryImAlternateEntity.CompanyCustomersDTO> companyCustomers = response.body().getData().getCompanyCustomers();
                        if (companyCustomers != null) {
                            activity.showImWindow(companyCustomers);
                        }
                    }
                } else {
                    MToast.showToast(activity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<EnquiryImAlternateEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getCompanyStatus(String companyNo, String companyName) {
        if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
            DialogHelper.showProgressDialog(activity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        NewAPIManager.getInstance().getGoodsAPI().getCompanyStatus(companyNo).enqueue(new Callback<BaseEntity<CompanyStatusEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<CompanyStatusEntity>> call, Response<BaseEntity<CompanyStatusEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    if ("0".equals(response.body().getData().companyStatus)) {
                        activity.checkTokenView();
                    } else {
                        new RoundDialog.Builder(activity)
                                .title("温馨提示")
                                .content("您当前的企业：【" + companyName + "】已被注销")
                                .confirm("知道了")
                                .singleBtn(true)
                                .contentGravity(Gravity.CENTER)
                                .cancelable(true)
                                .show();
                    }
                } else {
                    MToast.showToast(activity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<CompanyStatusEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }


    //1.5.7 商品首页询价新增token失效的校验，后端提议用这个接口来判断
    public void getCheckUserInfo() {
        DialogHelper.showProgressDialog(activity, null, "请求中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getUserAPI().getUserInfo().enqueue(new Callback<BaseEntity<UserMsgEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<UserMsgEntity>> call, Response<BaseEntity<UserMsgEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) return;
                if (response.body().getData() == null) return;
                if (response.body().getState().equals("ok")) {
                    activity.buildInquiryReleaseParam();
                } else {
                    MToast.showToast(activity, "登录过期,请重新登录");
                    ActivityJump.startActivity(AppRouteConstant.VerificationCodeLoginActivity, Pair.create("isJump", false));
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<UserMsgEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }
}
